import { ADDUSER, GETUSERACCOUNT } from "../constant"

const initPre = {
    count: 0,
    userData: JSON.parse(sessionStorage.getItem("user") as string) || null,
    accountData: []
}
interface action {
    type: String,
    data: any
}

export default function countReducer(preState = initPre, action: action) {
    const { type, data } = action
    switch (type) {
        case ADDUSER:

            sessionStorage.setItem("user", JSON.stringify(data))
            return { ...preState, userData: data }

        case GETUSERACCOUNT:

            return { ...preState, accountData: data }

        default:
            return preState
    }
}
